package com.fanfanwang.ffw.app.asynctask;

import java.util.LinkedHashMap;

import org.json.JSONException;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;

import com.fanfanwang.ffw.app.bean.SucAddParkNum;
import com.fanfanwang.ffw.app.bean.SucDelParkNum;
import com.fanfanwang.ffw.app.bean.SucParkNumBean;
import com.fanfanwang.ffw.app.bean.SucSetParknumStatusBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;
import com.fanfanwang.ffw.app.tenant.R;



public class SetParknumStatusAsyncTask extends IssAsyncTask<String, String, SucSetParknumStatusBean> {
	private Activity mActivity;
	private String park_id;
	private String status;
	public SetParknumStatusAsyncTask(Activity activity,String park_id,String status) {
		super(activity);
		mActivity = activity;
		this.park_id=park_id;
		this.status=status;
	}

	@Override
	protected SucSetParknumStatusBean doInBackground(String... params) {
		// TODO 	addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucSetParknumStatusBean sucSetParknumStatusBean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("park_id", park_id);
		paramsMap.put("status", status);
		try {
			sucSetParknumStatusBean = IssNetLib.getInstance(mActivity).setParknumStatus(WebServiceHelper._SETPARKNUMSTATUS, paramsMap);
		} catch (HttpRequestException e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_net_error);
		} catch (JSONException e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_json);
		}
		return sucSetParknumStatusBean;
	}

	@Override
	protected void onPostExecute(SucSetParknumStatusBean result) {
		super.onPostExecute(result);
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {
				ToastAlone.showToast(mActivity,mActivity.getResources().getString(R.string.set_status_success));
			}else if(result.status == 0){
				if (result.msg != null && !TextUtils.isEmpty(result.msg)) {
					ToastAlone.showToast(mActivity,com.fanfanwang.ffw.app.AppConstant.URLDecoderString(result.msg));
				} else {
					ToastAlone.showToast(mActivity,mActivity.getResources().getString(R.string.e_net_error));
				}
			}
		}
	}
}
